/*
 * lib2Desa - Another 2D game library in C++
 * Copyright (C) 2009 Erivaldo Xavier de Lima Filho
 *
 * This program is free software and is distributed under GNU General Public License version 3. You can modify and/or redistribute
 * it under the terms of GPL version 3 or posterior version. This program comes with NO WARRANTY, for more details, see LICENSE,
 * or <http://www.gnu.org/licenses>.
 *
 * Contact info:
 *
 *	Erivaldo Xavier de Lima Filho, desadoc@gmail.com
 *
 */

#include "SDL/Sync.hpp"

#include "SDL/SDL.h"

static u64 get_time(void)
{
	return SDL_GetTicks();
}

#ifndef _NO_NAMESPACE
namespace lib2Desa {
#endif

namespace SDL {

Sync::Sync(u32 ml)
: ASync(ml), elapsed(0), last(0)
{

}

void Sync::wait(void)
{
	unsigned long int t = get_time();
	elapsed = t - last;
	last = t;

	if(elapsed > milis) return;
	else
	{
		SDL_Delay((milis-elapsed));
	}
}

}

#ifndef _NO_NAMESPACE
}
#endif
